import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  HttpException,
  UseFilters,
  ForbiddenException,
  ParseIntPipe,
  UsePipes,
  UseInterceptors,
} from '@nestjs/common';
import { CatService } from './cat.service';
import { CreateCatDto } from './dto/create-cat.dto';
import { UpdateCatDto } from './dto/update-cat.dto';
import { HttpExceptionFilter } from '../filters/http-exception.filter';
import { createCatSchema } from './dto/create-cat.schema';
import { ValidationPipe } from '../pipes/validation.pipe';
import { LoggingInterceptor } from '../interceptors/logging,interceptor';
import { Public } from '../meta/Public';

@Controller('cat')
// @UseInterceptors(LoggingInterceptor)
export class CatController {
  constructor(private readonly catService: CatService) {}

  @Post()
  // @HttpCode(205)
  @UsePipes(new ValidationPipe(createCatSchema))
  create(@Body() createCatDto: CreateCatDto) {
    return this.catService.create(createCatDto);
    // throw new ForbiddenException();
  }

  @Get()
  @Public()
  findAll() {
    return this.catService.findAll();
  }

  @Get(':id')
  findOne(@Param('id', ParseIntPipe) id: number) {
    const s = null;
    console.log(s.length);
    return this.catService.findOne(id);
  }

  // @Get('a*c')
  // findByReg() {
  //   return 'find by reg';
  // }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateCatDto: UpdateCatDto) {
    return this.catService.update(+id, updateCatDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.catService.remove(+id);
  }
}
